package com.sendpo.zjx.sendpo.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.sendpo.zjx.sendpo.R;
import com.sendpo.zjx.sendpo.domain.ProduceOrderInfoDomain;
import com.sendpo.zjx.sendpo.net.HttpUrl;
import com.sendpo.zjx.sendpo.utils.Tools;
import com.sendpo.zjx.sendpo.utils.Xutils;

import org.json.JSONObject;
import org.xutils.common.Callback;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 朱俊鑫 on 2018
 */

public class MerchandiseOrderInfoActivity extends AppCompatActivity {

    @BindView(R.id.backbt)
    RelativeLayout backbt;
    @BindView(R.id.head)
    RelativeLayout head;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.head_img)
    ImageView headImg;
    @BindView(R.id.buynum)
    TextView buynum;
    @BindView(R.id.ordermoney)
    TextView ordermoney;
    @BindView(R.id.jifenpay_type)
    TextView jifenpayType;
    @BindView(R.id.jifenmoney)
    TextView jifenmoney;
    @BindView(R.id.song_type)
    TextView songType;
    @BindView(R.id.orderpindan_type)
    TextView orderpindanType;
    @BindView(R.id.ordermethod)
    TextView ordermethod;
    @BindView(R.id.orderpeople)
    TextView orderpeople;
    @BindView(R.id.orderphone)
    TextView orderphone;
    @BindView(R.id.orderaddress)
    TextView orderaddress;
    @BindView(R.id.ordercall)
    TextView ordercall;
 private  int orderid=0;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_merchandiseorderinfo);
        ButterKnife.bind(this);
        Tools.initStatus(this, R.color.black);
        initComponent();
    }

    private void initComponent() {
        orderid=getIntent().getIntExtra("id",0);
        query(orderid+"");
    }
    @OnClick(value = {R.id.backbt})
    public void onmyClick(View view){
        switch (view.getId()){
            case R.id.backbt:
                finish();
                break;
        }
    }

    public void query(String orderId){
      Map<String,String> map=new HashMap<>();
      map.put("id",""+orderId);

        Xutils.GET(HttpUrl.getByOrderId, map, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Gson gson=new Gson();
                ProduceOrderInfoDomain   domain=gson.fromJson(result,ProduceOrderInfoDomain.class);
                          if(domain.isFlag()){
                              ProduceOrderInfoDomain.DataBean.ProductOrderProductInfoBeansBean data=domain.getData().getProductOrderProductInfoBeans().get(0);
                              name.setText(""+data.getProductName());
                              Glide.with(MerchandiseOrderInfoActivity.this)
                                      .load(""+data.getMerchantsImg())
                                      .asBitmap()
                                      .centerCrop()
                                      .into(headImg);
                              buynum.setText("购买数量：" +data.getCount());
                              ordermoney.setText("总支付金额：¥" +data.getProductPrice());
                           if(domain.getData().getDeliveryType()==0){
                               ordermethod.setText("收货方式：配送");
                           }else{
                               ordermethod.setText("收货方式：自取");
                           }
                          }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Toast.makeText(getApplicationContext(),"请受再试",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
